﻿#include "kbe.h"
#include "kbeapp.h"
#include "kbeconfig.h"
#include "common/resmgr.h"
#include "helper/log.h"

using namespace xpy;

KBEApp* g_app = nullptr;

bool KBE_Init()
{
    ResMgr::instance();   // 需要执行这一句，创建一个实例。如果没有创建实例，访问没有初始化的成员变量会出问题

    KBEConfig *pConfig = new KBEConfig();
    std::string jsonStr = ResMgr::getInstance()->readFileText(ResMgr::getInstance()->getResPath() + "/kbengine.json");
    if (!pConfig->loadJsonStr(jsonStr.c_str()))
    {
        logger::error("loadJsonStr() is error!\n");
        return false;
    }

	if (g_app == nullptr)
		g_app = new KBEApp(pConfig);

    //delete pConfig;

    // TODO: 初始化Python
    return true;
}

bool KBE_Destroy()
{
    return true;
}
